﻿Public Class FormGBQJZJ
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Public usr As String
    Dim txt As TextBox
    Dim objMstTechnology As New clsMstTechnology
    Dim objGjbMst As New clsGjbMst
    Dim objFlbMst As New clsFlbMst
    Private objGbqxzj As New clsGBQXZJ
    Private update_status As String = "INSERT_TYPE"
    Private en As entity_gbqxzj
    Private _sys_id As String
    Public Property Sys_id As String
        Get
            Return _sys_id
        End Get
        Set(value As String)
            _sys_id = value
        End Set
    End Property

    Private Sub FormGBQJZJ_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = GetIniFile("JS", "JS7", "", g_jsInitFileName)
        txtDate.Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True
        txtDate.Properties.VistaEditTime = DevExpress.Utils.DefaultBoolean.True
        initForm()
        If _sys_id <> "" Then
            update_status = "UPDATE_TYPE"
            setContentBySysid()
        Else
            update_status = "INSERT_TYPE"
        End If
    End Sub

    Private Sub SetCmbData()
        Dim dtMst As New DataTable
        If rb_gjb.Checked Then
            dtMst = objGjbMst.selectAll(String.Empty)
        End If
        If rb_flb.Checked Then
            dtMst = objFlbMst.selectAll(String.Empty)
        End If
        cmb_type_value.ValueMember = "mst_value"
        cmb_type_value.DisplayMember = "mst_value_name"
        cmb_type_value.DataSource = dtMst
        If dtMst.Rows.Count > 0 Then
            cmb_type_value.SelectedIndex = 0
        End If
    End Sub

    Private Sub initForm()
        Dim reasons As String = GetIniFile("CLEAN", "REASON", "", g_jsInitFileName)
        Dim reasonList As String() = reasons.Split("，")
        cmbReason.Items.Clear()
        cmbReason.Items.Add(String.Empty)
        For index = 0 To reasonList.Count() - 1
            cmbReason.Items.Add(reasonList(index))
        Next
        If cmbReason.Items.Count > 0 Then
            cmbReason.SelectedIndex = 0
        End If
        Dim solutions As String = GetIniFile("CLEAN", "SOLUTION", "", g_jsInitFileName)
        Dim solutionList As String() = solutions.Split("，")
        cmbSolution.Items.Clear()
        cmbSolution.Items.Add(String.Empty)
        For index = 0 To solutionList.Count() - 1
            cmbSolution.Items.Add(solutionList(index))
        Next
        If cmbSolution.Items.Count > 0 Then
            cmbSolution.SelectedIndex = 0
        End If
        Dim dtMstTechnology As DataTable = objMstTechnology.getListByName(Me.Text)
        If dtMstTechnology.Rows.Count > 0 Then
            txtId.Text = dtMstTechnology.Rows(0)("sys_id").ToString()
            txtRequirement.Text = dtMstTechnology.Rows(0)("requirement").ToString()
            rb_gjb.Checked = True
            Dim TDate As String = Now.ToString()
            txtDate.Text = TDate
            rdo_clean_OK.Checked = True
            rdo_defect_OK.Checked = True
            rdo_clean1_OK.Checked = True
            rdo_rust_OK.Checked = True
            txt_check_value.Value = 0
            txt_ng_value.Value = 0
            cmbReason.Text = String.Empty
            cmbSolution.Text = String.Empty
        End If
    End Sub

    Private Sub setContentBySysid()
        Dim dt As DataTable = objGbqxzj.selectBySysid(_sys_id)
        If dt.Rows.Count > 0 Then
            Dim row As DataRow = dt.Rows(0)
            If row("oper_type") = 0 Then
                rb_gjb.Checked = True
            End If
            If row("oper_type") = 1 Then
                rb_flb.Checked = True
            End If
            txtDate.Text = row("oper_date")
            cmb_type_value.Text = row("type_value")
            If row("clean_value") = 1 Then
                rdo_clean_OK.Checked = True
            End If
            If row("clean_value") = 0 Then
                rdo_clean_NG.Checked = True
            End If
            If row("defect_value") = 1 Then
                rdo_defect_OK.Checked = True
            End If
            If row("defect_value") = 0 Then
                rdo_defect_NG.Checked = True
            End If

            If row("cleaning_value") = 1 Then
                rdo_clean1_OK.Checked = True
            End If
            If row("cleaning_value") = 0 Then
                rdo_clean1_NG.Checked = True
            End If

            If row("rust_value") = 1 Then
                rdo_rust_OK.Checked = True
            End If
            If row("rust_value") = 0 Then
                rdo_rust_NG.Checked = True
            End If

            txt_check_value.Text = row("check_value")
            txt_ng_value.Text = row("ng_value")
            cmbReason.Text = row("ng_reason")
            cmbSolution.Text = row("ng_solution")
        End If
    End Sub

    Private Sub txt_num_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_ng_value.MouseDown, txt_check_value.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub


    Private Sub setEntity()
        en = New entity_gbqxzj
        With en
            .sys_id = _sys_id
            .factory_id = "TS"
            .technology_id = txtId.Text
            .oper_date = txtDate.Text
            .oper_type = IIf(rb_gjb.Checked = True, "0", "1")
            .type_value = cmb_type_value.Text
            .clean_value = IIf(rdo_clean_OK.Checked = True, "1", "0")
            .defect_value = IIf(rdo_defect_OK.Checked = True, "1", "0")
            .cleaning_value = IIf(rdo_clean1_OK.Checked = True, "1", "0")
            .rust_value = IIf(rdo_rust_OK.Checked = True, "1", "0")
            .check_value = txt_check_value.Text
            .ng_value = txt_ng_value.Text
            .ng_reason = cmbReason.Text
            .ng_solution = cmbSolution.Text
            .oper = usr
        End With

    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If String.IsNullOrEmpty(txtDate.Text.Trim()) Then
            MsgBox("请选择日期", vbYes, "提示")
            Exit Sub
        End If
        If txt_check_value.Value <= 0 Then
            MsgBox("检查数需大于0", vbYes, "提示")
            Exit Sub
        End If
        If CInt(txt_ng_value.Text.Trim()) > CInt(txt_check_value.Text.Trim()) Then
            MsgBox("不合格数需小于等于检测数", vbYes, "提示")
            Exit Sub
        End If
        If txt_ng_value.Value > 0 Then
            If String.IsNullOrEmpty(cmbReason.Text.Trim()) Then
                MsgBox("请选择不合格原因", vbYes, "提示")
                Exit Sub
            End If
            If String.IsNullOrEmpty(cmbSolution.Text.Trim()) Then
                MsgBox("请选择解决措施", vbYes, "提示")
                Exit Sub
            End If
        End If
        If String.IsNullOrEmpty(txtDate.Text.Trim()) Then
            MsgBox("请选择操作日期", vbYes, "提示")
            Exit Sub
        End If
        setEntity()
        If update_status = "INSERT_TYPE" Then
            If objGbqxzj.insert(en) <> -2 Then
                MsgBox("保存成功", vbYes, "提示")
                initForm()
            Else
                MsgBox("保存失败", vbYes, "提示")
            End If
        End If
        If update_status = "UPDATE_TYPE" Then
            If objGbqxzj.update(en) <> -2 Then
                MsgBox("保存成功", vbYes, "提示")
                CType(Owner, FormGBQJZJRecord).setDgvData()
                Close()
            Else
                MsgBox("保存失败", vbYes, "提示")
            End If
        End If
    End Sub

    Private Sub rb_gjb_CheckedChanged(sender As Object, e As EventArgs) Handles rb_gjb.CheckedChanged
        SetCmbData()
    End Sub

    Private Sub rb_flb_CheckedChanged(sender As Object, e As EventArgs) Handles rb_flb.CheckedChanged
        SetCmbData()
    End Sub

End Class

Public Class entity_gbqxzj
    Public sys_id As String
    Public factory_id As String
    Public technology_id As String
    Public oper_date As String
    Public oper_type As String
    Public type_value As String
    Public clean_value As String
    Public defect_value As String
    Public cleaning_value As String
    Public rust_value As String
    Public check_value As String
    Public ng_value As String
    Public ng_reason As String
    Public ng_solution As String
    Public oper As String
    Public update_time As String
End Class